package com.lxk.mall.pms.controller.app.vo;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.AssertTrue;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.dromara.common.core.utils.PageParam;

import java.util.List;

/**
 * 用户 App - 商品 SPU 分页 Request VO
 */
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class AppProductSpuPageReqVO extends PageParam {

    public static final String SORT_FIELD_PRICE = "price";
    public static final String SORT_FIELD_SALES_COUNT = "salesCount";
    public static final String SORT_FIELD_CREATE_TIME = "createTime";

    /**
     * 商品 SPU 编号数组
     */
    private List<Long> ids;

    /**
     * 分类编号
     */
    private Long categoryId;

    /**
     * 分类编号数组
     */
    private List<Long> categoryIds;

    /**
     * 关键字
     */
    private String keyword;

    /**
     * 排序字段
      */
// 参见 AppProductSpuPageReqVO.SORT_FIELD_XXX 常量
    private String sortField;

    /**
     * 排序方式
     */
    private Boolean sortAsc;

    @AssertTrue(message = "排序字段不合法")
    @JsonIgnore
    public boolean isSortFieldValid() {
        if (StrUtil.isEmpty(sortField)) {
            return true;
        }
        return StrUtil.equalsAny(sortField, SORT_FIELD_PRICE, SORT_FIELD_SALES_COUNT);
    }

}
